<?php
namespace Site\Controller;

class UserController extends CommonController {

    public function signin() {
        if(IS_POST) {
            $username = I('post.username');
            verify($username,'notEmpty','用户名/邮箱不能为空');

            $password = I('post.password');
            verify($password,'notEmpty','密码不能为空');

            $verify = I('post.verify');
            verify($verify,'notEmpty','验证码不能为空');

            if(!(new \Think\Verify)->check($verify)) $this->error('验证码错误');

            if(C('password') !== md5($password)) $this->error('密码错误');

            session('username',C('username'));

            $this->redirect('/');
        }
        $this->layout = false;
        $this->display();
    }

    public function verify() {
        $Verify = new \Think\Verify();
        $Verify->expire = 600;
        $Verify->fontSize = 16;
        $Verify->imageW = 150;
        $Verify->imageH = 37;
        $Verify->length = 5;
        $Verify->useNoise = true;
        $Verify->useCurve = false;
        $Verify->entry();
    }

    public function signout() {
        session(null);
        $this->redirect('/user/signin');
    }
}
?>
